import java.util.HashMap;

/*
 * @lc app=leetcode.cn id=36 lang=java
 *
 * [36] 有效的数独
 */

// @lc code=start
class Solution {
    public boolean isValidSudoku(char[][] board) {
        //数字有0-9 共10个
        int[][] rols = new int[9][10];
        int[][] cols = new int[9][10];
        int[][] boxes = new int[9][10];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if(board[i][j] != '.'){
                    int num = board[i][j] - '0';
                    int box_index = (i / 3) * 3 + (j / 3);
                    rols[i][num]++;
                    cols[j][num]++;
                    boxes[box_index][num]++;
                    if(rols[i][num] > 1 || cols[j][num] > 1 || boxes[box_index][num] > 1){
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
// @lc code=end

